#ifndef _SHD_HULL_HLSL_
#define _SHD_HULL_HLSL_

#include "./shd_vertex.hlsl"

//--------------------------------------------------------------------------------------
// Constant data function for the ConstantHS.  This is executed once per patch.
//--------------------------------------------------------------------------------------
struct HS_CONSTANT_DATA_OUTPUT {
	float Edges[4]			: SV_TessFactor;
	float Inside[2]			: SV_InsideTessFactor;
};

struct HS_OUTPUT {
	int vIndex			: INDEX;
	float3 vPosition	: POSITION;
	float3 vTangent		: TANGENT;
};

// This constant hull shader is executed once per patch.  
// In this sample, we set the tessellation factor
// via SV_TessFactor and SV_InsideTessFactor for each patch.  In a more complex scene,
// you might calculate a variable tessellation factor based on the camera's distance.

HS_CONSTANT_DATA_OUTPUT ConstantHS( InputPatch<VS_CONTROL_POINT_OUTPUT, INPUT_PATCH_SIZE> ip,
											uint PatchID : SV_PrimitiveID ) {

	HS_CONSTANT_DATA_OUTPUT Output;

	float TessAmount = g_fTessellationFactor;

	Output.Edges[0] = Output.Edges[1] = Output.Edges[2] = Output.Edges[3] = TessAmount;
	Output.Inside[0] = Output.Inside[1] = TessAmount;

	return Output;

};

// The hull shader is called once per output control point, which is specified with
// outputcontrolpoints.  For this sample, we take the control points from the vertex
// shader and pass them directly off to the domain shader.  In a more complex scene,
// you might perform a basis conversion from the input control points into a Bezier
// patch, such as the SubD11 DirectX SDK Sample.

// The input to the hull shader comes from the vertex shader

// The output from the hull shader will go to the domain shader.
// The tessellation factor, topology, and partition mode will go to the fixed function
// tessellator stage to calculate the UVW and domain points.

[domain("quad")]
[partitioning(HS_PARTITION)]
[outputtopology("triangle_cw")]
[outputcontrolpoints(OUTPUT_PATCH_SIZE)]
[patchconstantfunc("ConstantHS")]
HS_OUTPUT HS( InputPatch<VS_CONTROL_POINT_OUTPUT, INPUT_PATCH_SIZE> p, 
					uint i : SV_OutputControlPointID,
					uint PatchID : SV_PrimitiveID ) {

	HS_OUTPUT Output;
	Output.vIndex = p[i].vIndex;
	Output.vPosition = p[i].vPosition;
	Output.vTangent = p[i].vTangent;
	return Output;

};


#endif // _SHD_HULL_HLSL_
